﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.IO.Ports;
using System.Collections;
using System.Windows.Forms;
using Newtonsoft.Json;

namespace JLM2
{
    public class JLMComm
    {
        private SerialPort serialPortInstance = null;
        private bool serialPortOpened = false;
        JLMPLCCommands jlmPLCommand = new JLMPLCCommands(@"jlm.json");
        Queue commQueue = null;

        public JLMComm()
        {
            commQueue = new Queue();
        }

        public bool Open(string portNum)
        {
            try
            {
                serialPortInstance = new SerialPort(portNum);

                //波特率 
                serialPortInstance.BaudRate = 9600;

                //奇偶校验位 无奇偶校验位
                serialPortInstance.Parity = Parity.Even;

                //停止位 一个停止位
                serialPortInstance.StopBits = StopBits.One;

                //数据位 8位数据位
                serialPortInstance.DataBits = 7;

                //设置串口协议
                serialPortInstance.Handshake = Handshake.None;

                //是否启用串口发送 启用串口发送
                serialPortInstance.RtsEnable = true;

                serialPortInstance.ReadTimeout = 500;

                // 设置接收委托
                // jlSerialPort.DataReceived += new SerialDataReceivedEventHandler(serialPortOnDataReceived);
                //开启串口
                serialPortInstance.Open();
                serialPortOpened = true;
            }
            catch (SystemException e)
            {
                serialPortOpened = false;
            }

            return serialPortOpened;
        }

        public void Close()
        {
            serialPortInstance.Close();
            serialPortOpened = false;
        }
        /// <summary>
        /// 配置一个脚轮参数
        /// </summary>
        private void WriteAJLMParam(string param, bool paramIsNum, string configCmd)
        {
            ushort value = 0;
            byte[] arrayValue = null;
            if (param.Length == 0)
            {
                return;
            }
            if (!serialPortOpened)
            {
                return;
            }

            try
            {
                if (paramIsNum) // 参数是数字类型
                {
                    value = Convert.ToUInt16(param); // 先转为数字
                    arrayValue = BitConverter.GetBytes(value); // 转为数组
                    Array.Reverse(arrayValue); // 反转
                }
                else
                {
                    arrayValue = Encoding.ASCII.GetBytes(param); // 直接取ASCII数组
                }

                // 将值格式化为16进制字符串
                StringBuilder builder = new StringBuilder();
                for (int i = 0; i < arrayValue.Length; i++)
                {
                    builder.Append(string.Format("{0:X2} ", arrayValue[i]));
                }
                string hexStringValue = builder.ToString(); // 值的16进制字符串

                string cmd = configCmd + " " + hexStringValue; // 配置文件中的命令字符串
                cmd = cmd.ToUpper(); // 替换参数

                // 计算LRC校验，并组合为PLC命令串
                string lrc = Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16);
                if (lrc.Length == 1)
                {
                    lrc = "0" + lrc;
                }
                string cmd2 = ":" + cmd + lrc + "\r\n";

                // 移除空格并转为大写
                cmd2 = cmd2.Replace(" ", "").ToUpper();

                // 发送
                serialPortInstance.Write(cmd2);
                JLMLog.Write("=> " + cmd2);
                Thread.Sleep(20);
                // 接收
                cmd2 = serialPortInstance.ReadLine();
                JLMLog.Write("<= " + cmd2);
            }
            catch (SystemException se)
            {
            }
        }


        private void WriteAJLMParam2(string param, bool paramIsNum, string configCmd)
        {
            UInt32 value = 0;
            byte[] arrayValue = null;
            if (param.Length == 0)
            {
                return;
            }
            if (!serialPortOpened)
            {
                return;
            }

            try
            {
                if (paramIsNum) // 参数是数字类型
                {
                    value = Convert.ToUInt32(param); // 先转为数字
                    arrayValue = BitConverter.GetBytes(value); // 转为数组
                    Array.Reverse(arrayValue); // 反转
                }
                else
                {
                    arrayValue = Encoding.ASCII.GetBytes(param); // 直接取ASCII数组
                }

                // 将值格式化为16进制字符串
                StringBuilder builder = new StringBuilder();
                for (int i = 0; i < arrayValue.Length; i++)
                {
                    builder.Append(string.Format("{0:X2} ", arrayValue[i]));
                }
                string hexStringValue = builder.ToString(); // 值的16进制字符串

                // string cmd = configCmd + " " + hexStringValue; // 配置文件中的命令字符串
                string temp = hexStringValue;
                string cmd = "01 06 12 0b " + temp.Substring(0, 5); // 00 00 00 00
                cmd = cmd.ToUpper(); // 替换参数

                // 计算LRC校验，并组合为PLC命令串
                string lrc = Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16);
                if (lrc.Length == 1)
                {
                    lrc = "0" + lrc;
                }
                string cmd2 = ":" + cmd + lrc + "\r\n";

                // 移除空格并转为大写
                cmd2 = cmd2.Replace(" ", "").ToUpper();

                // 发送
                serialPortInstance.Write(cmd2);
                JLMLog.Write("=> " + cmd2);
                Thread.Sleep(20);
                // 接收
                cmd2 = serialPortInstance.ReadLine();
                JLMLog.Write("<= " + cmd2);


                ///
                cmd = "01 06 12 0a " + temp.Substring(6, 5);
                cmd = cmd.ToUpper(); // 替换参数

                // 计算LRC校验，并组合为PLC命令串
                lrc = Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16);
                if (lrc.Length == 1)
                {
                    lrc = "0" + lrc;
                }
                cmd2 = ":" + cmd + lrc + "\r\n";

                // 移除空格并转为大写
                cmd2 = cmd2.Replace(" ", "").ToUpper();

                // 发送
                serialPortInstance.Write(cmd2);
                JLMLog.Write("=> " + cmd2);
                Thread.Sleep(20);
                // 接收
                cmd2 = serialPortInstance.ReadLine();
                JLMLog.Write("<= " + cmd2);
            }
            catch (SystemException se)
            {
            }
        }

        #region 读取产品信息
        /// 读取产品名称信息 从D2070 - 2079
        private string ReadProductMC()
        {
            lock (serialPortInstance)
            {
                try
                {
                    string cmd = "", result = "";
                    cmd = "01 03 18 16 00 0a";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    JLMLog.Write("=> " + cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine();
                    JLMLog.Write("<= " + result);

                    char[] aa = new char[20];
                    string av = result.Substring(7, 2);
                    aa[0] = (char)Convert.ToByte(av, 16);
                    av = result.Substring(9, 2);
                    aa[1] = (char)Convert.ToByte(av, 16);
                    av = result.Substring(11, 2);
                    aa[2] = (char)Convert.ToByte(av, 16);
                    av = result.Substring(13, 2);
                    aa[3] = (char)Convert.ToByte(av, 16);
                    av = result.Substring(15, 2);
                    aa[4] = (char)Convert.ToByte(av, 16);
                    av = result.Substring(17, 2);
                    aa[5] = (char)Convert.ToByte(av, 16);
                    av = result.Substring(19, 2);
                    aa[6] = (char)Convert.ToByte(av, 16);
                    av = result.Substring(21, 2);
                    aa[7] = (char)Convert.ToByte(av, 16);
                    av = result.Substring(23, 2);
                    aa[8] = (char)Convert.ToByte(av, 16);
                    av = result.Substring(25, 2);
                    aa[9] = (char)Convert.ToByte(av, 16);
                    return new string(aa);
                }
                catch (SystemException se)
                {

                }
            }
            return "";
        }

        // 读取产品图号
        private string ReadProductTH()
        {
            lock (serialPortInstance)
            {
                try
                {
                    string cmd = "", result = "";
                    cmd = "01 03 18 20 00 0a";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    JLMLog.Write("=> " + cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine();
                    JLMLog.Write("<= " + result);

                    char[] aa = new char[20];
                    string av = result.Substring(7, 2);
                    aa[0] = (char)Convert.ToByte(av, 16);
                    av = result.Substring(9, 2);
                    aa[1] = (char)Convert.ToByte(av, 16);
                    av = result.Substring(11, 2);
                    aa[2] = (char)Convert.ToByte(av, 16);
                    av = result.Substring(13, 2);
                    aa[3] = (char)Convert.ToByte(av, 16);
                    av = result.Substring(15, 2);
                    aa[4] = (char)Convert.ToByte(av, 16);
                    av = result.Substring(17, 2);
                    aa[5] = (char)Convert.ToByte(av, 16);
                    av = result.Substring(19, 2);
                    aa[6] = (char)Convert.ToByte(av, 16);
                    av = result.Substring(21, 2);
                    aa[7] = (char)Convert.ToByte(av, 16);
                    av = result.Substring(23, 2);
                    aa[8] = (char)Convert.ToByte(av, 16);
                    av = result.Substring(25, 2);
                    aa[9] = (char)Convert.ToByte(av, 16);
                    return new string(aa);
                }
                catch (SystemException se)
                {

                }
            }
            return "";
        }

        // 读取产品材料
        private string ReadProductCL()
        {
            lock (serialPortInstance)
            {
                try
                {
                    string cmd = "", result = "";
                    cmd = "01 03 18 2a 00 0a";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    JLMLog.Write("=> " + cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine();
                    JLMLog.Write("<= " + result);
                    char[] aa = new char[20];
                    string av = result.Substring(7, 2);
                    aa[0] = (char)Convert.ToByte(av, 16);
                    av = result.Substring(9, 2);
                    aa[1] = (char)Convert.ToByte(av, 16);
                    av = result.Substring(11, 2);
                    aa[2] = (char)Convert.ToByte(av, 16);
                    av = result.Substring(13, 2);
                    aa[3] = (char)Convert.ToByte(av, 16);
                    av = result.Substring(15, 2);
                    aa[4] = (char)Convert.ToByte(av, 16);
                    av = result.Substring(17, 2);
                    aa[5] = (char)Convert.ToByte(av, 16);
                    av = result.Substring(19, 2);
                    aa[6] = (char)Convert.ToByte(av, 16);
                    av = result.Substring(21, 2);
                    aa[7] = (char)Convert.ToByte(av, 16);
                    av = result.Substring(23, 2);
                    aa[8] = (char)Convert.ToByte(av, 16);
                    av = result.Substring(25, 2);
                    aa[9] = (char)Convert.ToByte(av, 16);
                    return new string(aa);
                }
                catch (SystemException se)
                {

                }
            }
            return "";
        }

        // 读取产品编号
        private string ReadProductBH()
        {
            lock (serialPortInstance)
            {
                string cmd = "", result = "";
                int value = 0;
                if (!serialPortOpened)
                {
                    return "";
                }
                try
                {
                    // 读取产品编号
                    cmd = jlmPLCommand.cpDQBH + " 00 01";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    JLMLog.Write("=> " + cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine();
                    JLMLog.Write("<= " + result);
                    result = result.Substring(7, 4);
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    return value.ToString();
                }
                catch (SystemException se)
                {

                }
            }
            return "";
        }

        private string ReadProductWJ()
        {
            lock (serialPortInstance)
            {
                try
                {
                    string cmd = "", result = "";
                    int value = 0;
                    if (!serialPortOpened)
                    {
                        return "";
                    }
                    // 读取产品外径
                    cmd = jlmPLCommand.cpDQWJ + " 00 01";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    JLMLog.Write("=> " + cmd);
                    Thread.Sleep(20);
                    // 接收
                    // 接收
                    result = serialPortInstance.ReadLine();
                    JLMLog.Write("<= " + result);
                    result = result.Substring(7, 4);
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    return value.ToString();
                }
                catch (SystemException se)
                {

                }
            }
            return "";

        }

        private string ReadProductYD()
        {
            lock (serialPortInstance)
            {
                try
                {
                    string cmd = "", result = "";
                    int value = 0;
                    if (!serialPortOpened)
                    {
                        return "";
                    }
                    // 读取产品硬度
                    cmd = jlmPLCommand.cpDQYD + " 00 01";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    JLMLog.Write("=> " + cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine();
                    JLMLog.Write("<= " + result);
                    result = result.Substring(7, 4);
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    return value.ToString();
                }
                catch (SystemException se)
                {

                }
            }
            return "";
        }

        #endregion      

        #region 读取测试参数方法集
        private string ReadTestParamZXC()
        {
            lock (serialPortInstance)
            {
                string cmd = "", result = "";
                int value = 0;
                if (!serialPortOpened)
                {
                    return "";
                }

                try
                {
                    // 读取测试总行程 实例数据80000其16进制位13880 <= :010304388000013F 有效数据：38800001 低位在前3880 高位在后0001
                    cmd = jlmPLCommand.csDQZXC + " 00 02";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    serialPortInstance.Write(cmd);       // 发送
                    JLMLog.Write("=> " + cmd);
                    Thread.Sleep(20);
                    result = serialPortInstance.ReadLine();
                    JLMLog.Write("<= " + result);
                    result = result.Substring(7, 8);
                    value = Convert.ToInt32(JLMUtlity.Get32BitResult(result));
                    //string a = result.Substring(7, 4);
                    //string b = result.Substring(11, 4);
                    //result = b + a;
                    //value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    return value.ToString();
                }
                catch (SystemException se)
                {

                }
            }
            return "";
        }

        private string ReadTestParamSJ()
        {
            lock (serialPortInstance)
            {
                string cmd = "", result = "";
                int value = 0;
                if (!serialPortOpened)
                {
                    return "";
                }

                try
                {
                    // 读取时间
                    cmd = jlmPLCommand.csDQSJ + " 00 02";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    serialPortInstance.Write(cmd);       // 发送
                    JLMLog.Write("=> " + cmd);
                    Thread.Sleep(20);
                    result = serialPortInstance.ReadLine();
                    JLMLog.Write("<= " + result);
                    result = result.Substring(7, 8);
                    //value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    value = Convert.ToInt32(JLMUtlity.Get32BitResult(result)); // New 20241111
                    return value.ToString();
                }
                catch (SystemException se)
                {

                }
            }
            return "";
        }

        private string ReadTestParamZACS()
        {
            lock (serialPortInstance)
            {
                string cmd = "", result = "";
                int value = 0;
                if (!serialPortOpened)
                {
                    return "";
                }

                try
                {
                    // 读取障碍次数
                    cmd = jlmPLCommand.csDQZACS + " 00 02";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    serialPortInstance.Write(cmd);       // 发送
                    JLMLog.Write("=> " + cmd);
                    Thread.Sleep(20);
                    result = serialPortInstance.ReadLine();
                    JLMLog.Write("<= " + result);
                    result = result.Substring(7, 8);
                    //value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    value = Convert.ToInt32(JLMUtlity.Get32BitResult(result));
                    return value.ToString();
                }
                catch (SystemException se)
                {

                }
            }
            return "";
        }

        private string ReadTestParamCSFZ()
        {
            lock (serialPortInstance)
            {

                string cmd = "", result = "";
                int value = 0;
                if (!serialPortOpened)
                {
                    return "";
                }

                try
                {
                    // 读取测试负载
                    cmd = jlmPLCommand.csDQCSFZ + " 00 02";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    serialPortInstance.Write(cmd);       // 发送
                    JLMLog.Write("=> " + cmd);
                    Thread.Sleep(20);
                    result = serialPortInstance.ReadLine();
                    JLMLog.Write("<= " + result);
                    result = result.Substring(7, 8);
                    //value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    value = Convert.ToInt32(JLMUtlity.Get32BitResult(result));
                    return value.ToString();
                }
                catch (SystemException se)
                {

                }
            }
            return "";
        }

        private string ReadTestParamCSSD()
        {
            lock (serialPortInstance)
            {
                string cmd = "", result = "";
                int value = 0;
                if (!serialPortOpened)
                {
                    return "";
                }

                try
                {
                    // 读取测试速度
                    cmd = jlmPLCommand.csDQCSSD + " 00 01";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    serialPortInstance.Write(cmd);       // 发送
                    JLMLog.Write("=> " + cmd);
                    Thread.Sleep(20);
                    result = serialPortInstance.ReadLine();
                    JLMLog.Write("<= " + result);
                    result = result.Substring(7, 4);
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    return value.ToString();
                }
                catch (SystemException se)
                {

                }
            }
            return "";
        }

        private string ReadTestParamZWWGD()
        {
            string cmd = "", result = "";
            int value = 0;
            lock (serialPortInstance)
            {
                if (!serialPortOpened)
                {
                    return "";
                }

                try
                {
                    // 读取障碍物高度
                    cmd = jlmPLCommand.csDQZWWGD + " 00 01";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    serialPortInstance.Write(cmd);       // 发送
                    JLMLog.Write("=> " + cmd);
                    Thread.Sleep(20);
                    result = serialPortInstance.ReadLine();
                    JLMLog.Write("<= " + result);
                    result = result.Substring(7, 4);
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    return value.ToString();
                }
                catch (SystemException se)
                {

                }
            }
            return "";
        }
        #endregion

        #region 读取测试模式的参数
        private string ReadTestModeParamZZSJ(bool lockSerialPort = true)
        {
            if (lockSerialPort)
            {
                lock (serialPortInstance)
                {
                    string cmd = "", result = "";
                    int value = 1000;

                    if (!serialPortOpened)
                    {
                        return "";
                    }

                    try
                    {
                        // 读取正转时间参数
                        cmd = jlmPLCommand.yxDQZZSJ + " 00 01";
                        cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                        cmd = cmd.Replace(" ", "").ToUpper();
                        // 发送
                        serialPortInstance.Write(cmd);
                        JLMLog.Write("=> " + cmd);
                        Thread.Sleep(20);
                        // 接收
                        result = serialPortInstance.ReadLine();
                        JLMLog.Write("<= " + result);
                        result = result.Substring(7, 4);
                        value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    }
                    catch (SystemException se)
                    {

                    }
                    return value.ToString();
                }
            }
            else
            {
                string cmd = "", result = "";
                int value = 1000;

                if (!serialPortOpened)
                {
                    return "";
                }

                try
                {
                    // 读取正转时间参数
                    cmd = jlmPLCommand.yxDQZZSJ + " 00 01";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    JLMLog.Write("=> " + cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine();
                    JLMLog.Write("<= " + result);
                    result = result.Substring(7, 4);
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                }
                catch (SystemException se)
                {

                }
                return value.ToString();
            }
        }

        private string ReadTestModeParamFZSJ(bool lockSerialPort = true)
        {
            string cmd = "", result = "";
            int value = 0;

            if (lockSerialPort)
            {
                lock (serialPortInstance)
                {
                    if (!serialPortOpened)
                    {
                        return "";
                    }

                    try
                    {
                        // 读取反转时间参数
                        cmd = jlmPLCommand.yxDQFZSJ + " 00 01";
                        cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                        cmd = cmd.Replace(" ", "").ToUpper();
                        // 发送
                        serialPortInstance.Write(cmd);
                        JLMLog.Write("=> " + cmd);
                        Thread.Sleep(20);
                        // 接收
                        result = serialPortInstance.ReadLine();
                        JLMLog.Write("<= " + result);
                        result = result.Substring(7, 4);
                        value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    }
                    catch (SystemException se)
                    {

                    }
                    return value.ToString();
                }
            }
            else
            {
                if (!serialPortOpened)
                {
                    return "";
                }

                try
                {
                    // 读取反转时间参数
                    cmd = jlmPLCommand.yxDQFZSJ + " 00 01";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    JLMLog.Write("=> " + cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine();
                    JLMLog.Write("<= " + result);
                    result = result.Substring(7, 4);
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                }
                catch (SystemException se)
                {

                }
                return value.ToString();
            }
        }

        private string ReadTestModeParamTDSJ(bool lockSerialPort = true)
        {
            string cmd = "", result = "";
            int value = 0;

            if (lockSerialPort)
            {
                lock (serialPortInstance)
                {
                    if (!serialPortOpened)
                    {
                        return "";
                    }

                    try
                    {
                        // 读取停顿时间参数
                        cmd = jlmPLCommand.yxDQTDSJ + " 00 01";
                        cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                        cmd = cmd.Replace(" ", "").ToUpper();
                        // 发送
                        serialPortInstance.Write(cmd);
                        JLMLog.Write("=> " + cmd);
                        Thread.Sleep(20);
                        // 接收
                        result = serialPortInstance.ReadLine();
                        JLMLog.Write("<= " + result);
                        result = result.Substring(7, 4);
                        value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    }
                    catch (SystemException se)
                    {

                    }
                    return value.ToString();
                }
            }
            else
            {
                if (!serialPortOpened)
                {
                    return "";
                }

                try
                {
                    // 读取停顿时间参数
                    cmd = jlmPLCommand.yxDQTDSJ + " 00 01";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    JLMLog.Write("=> " + cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine();
                    JLMLog.Write("<= " + result);
                    result = result.Substring(7, 4);
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                }
                catch (SystemException se)
                {

                }
                return value.ToString();
            }

        }

        #endregion

        #region 读取运行状态信息
        private int ReadRunStatusYXZT()
        {
            string cmd = "";
            int value = 0;
            string result = "";
            lock (serialPortInstance)
            {
                if (!serialPortOpened)
                {
                    return -1;
                }

                try
                {
                    // 读取运行状态
                    cmd = jlmPLCommand.yxZTJQZT + " 00 01";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    serialPortInstance.Write(cmd);       // 发送
                    JLMLog.Write("=> " + cmd);
                    Thread.Sleep(20);
                    result = serialPortInstance.ReadLine();
                    JLMLog.Write("<= " + result);
                    result = result.Substring(7, 4);
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                }
                catch (SystemException se)
                {

                }
                return value;
            }
        }

        private string ReadRunStatusDQXC()
        {
            string cmd = "";
            int value = 0;
            string result = "";
            lock (serialPortInstance)
            {
                try
                {
                    if (!serialPortOpened)
                    {
                        return "";
                    }

                    // 运行状态 当前行程
                    cmd = jlmPLCommand.yxZTDQXC + " 00 02";/// @2023.09.18 by Fanze
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    serialPortInstance.Write(cmd);
                    JLMLog.Write("=> " + cmd);
                    Thread.Sleep(20);
                    result = serialPortInstance.ReadLine();
                    JLMLog.Write("<= " + result);
                    string a = result.Substring(7, 4);
                    string b = result.Substring(11, 4);
                    result = b + a;
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                }
                catch (SystemException se)
                {

                }
                return value.ToString();
            }
        }

        private string ReadRunStatuPJSD()
        {
            string cmd = "";
            int value = 0;
            string result = "";
            float fv1 = 0.0f, fv2 = 0.0f;
            lock (serialPortInstance)
            {
                try
                {
                    if (!serialPortOpened)
                    {
                        return "";
                    }

                    // 运行状态 平均速度
                    cmd = jlmPLCommand.yxZTPJSD + " 00 01";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    JLMLog.Write("=> " + cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine();
                    JLMLog.Write("<= " + result);
                    result = result.Substring(7, 4);
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    fv2 = fv1 = value;
                    if (fv1 > 0)
                    {
                        fv2 = fv1 / 10.0f;
                    }
                }
                catch (SystemException se)
                {

                }
            }
            return fv2.ToString();

        }

        private string ReadRunStatuXZSD()
        {
            lock (serialPortInstance)
            {
                string cmd = "";
                int value = 0;
                string result = "";
                float fv1 = 0.0f, fv2 = 0.0f;
                try
                {
                    if (!serialPortOpened)
                    {
                        return "";
                    }

                    // 运行状态 现在速度
                    cmd = jlmPLCommand.yxZTXZSD + " 00 01";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    JLMLog.Write("=> " + cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine();
                    JLMLog.Write("<= " + result);
                    result = result.Substring(7, 4);
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    fv1 = fv2 = value;
                    if (fv2 > 0)
                    {
                        fv2 /= 10.0f;
                    }
                    return fv2.ToString();
                }
                catch (SystemException se)
                {

                }

                return fv2.ToString();
            }
        }

        private int ReadRunStatuYCSJ()
        {
            string cmd = "";
            int value = 0;
            string result = "";

            if (!serialPortOpened)
            {
                return 0;
            }
            lock (serialPortInstance)
            {
                try
                {
                    // 运行状态 已测时间
                    cmd = jlmPLCommand.yxZTYCSJ + " 00 01";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    JLMLog.Write("=> " + cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine();
                    JLMLog.Write("<= " + result);
                    result = result.Substring(7, 4);
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                }
                catch (SystemException se)
                {

                }
            }
            return value;
        }



        private int ReadRunStatuYCSJ2()
        {
            string cmd = "";
            int value = 0;
            string result = "";

            if (!serialPortOpened)
            {
                return 0;
            }
            lock (serialPortInstance)
            {
                try
                {
                    //cmd = jlmPLCommand.yxZTPZCS + " 00 02";
                    cmd = "01 03 12 4a 00 02";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    serialPortInstance.Write(cmd);       // 发送
                    JLMLog.Write("=> " + cmd);
                    Thread.Sleep(20);
                    result = serialPortInstance.ReadLine().Substring(7, 8);
                    value = Convert.ToInt32(JLMUtlity.Get32BitResult(result));
                    /*
                    // 读取测试总行程 实例数据80000其16进制位13880 <= :010304388000013F 有效数据：38800001 低位在前3880 高位在后0001
                    cmd = jlmPLCommand.yxZTPZCS + " 00 02";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    serialPortInstance.Write(cmd);       // 发送
                    JLMLog.Write("=> " + cmd);
                    Thread.Sleep(20);
                    result = serialPortInstance.ReadLine();
                    JLMLog.Write("<= " + result);
                    //result = result.Substring(7, 8);                    
                    string a = result.Substring(7, 4);
                    string b = result.Substring(11, 4);
                    result = b + a;
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    */
                }
                catch (SystemException se)
                {

                }
            }
            return value;
        }

        /// <summary>
        /// 读取测试状态 32b数据
        /// </summary>
        /// <returns></returns>
        private string ReadRunStatuPZCS2()
        {
            lock (serialPortInstance)
            {
                string cmd = "", result = "";
                int value = 0;
                if (!serialPortOpened)
                {
                    return "";
                }

                try
                {
                    // 读取测试总行程 实例数据80000其16进制位13880 <= :010304388000013F 有效数据：38800001 低位在前3880 高位在后0001
                    cmd = jlmPLCommand.yxZTPZCS + " 00 02";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    serialPortInstance.Write(cmd);       // 发送
                    JLMLog.Write("=> " + cmd);
                    Thread.Sleep(20);
                    result = serialPortInstance.ReadLine();
                    JLMLog.Write("<= " + result);
                    //result = result.Substring(7, 8);                    
                    string a = result.Substring(7, 4);
                    string b = result.Substring(11, 4);
                    result = b + a;
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    return value.ToString();
                }
                catch (SystemException se)
                {

                }
            }
            return "";
        }

        private string ReadRunStatuPZCS()
        {
            string cmd = "";
            int value = 0;
            string result = "";

            lock (serialPortInstance)
            {
                try
                {
                    if (!serialPortOpened)
                    {
                        return "";
                    }
                    // 运行状态 碰撞次数
                    cmd = jlmPLCommand.yxZTPZCS + " 00 01";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    JLMLog.Write("=> " + cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine();
                    JLMLog.Write("<= " + result);
                    result = result.Substring(7, 4);
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                }
                catch (SystemException se)
                {

                }
            }
            return value.ToString();
        }

        private int ReadRunStatuDQWD()
        {
            string cmd = "";
            int value = 0;
            string result = "";

            lock (serialPortInstance)
            {
                try
                {
                    // 运行状态 当前温度
                    cmd = jlmPLCommand.yxZTDQWD + " 00 01";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    JLMLog.Write("=> " + cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine();
                    JLMLog.Write("<= " + result);
                    result = result.Substring(7, 4);
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                }
                catch (SystemException se)
                {

                }
            }
            return value;
        }

        /// <summary>
        /// 首页读取温度3
        /// </summary>
        /// <returns></returns>
        private string ReadRunStatuDQWD3()
        {
            string value = "", cmd = "", result = "";
            float fv1, fv2;
            lock (serialPortInstance)
            {
                try
                {
                    // 读取当前温度3 D594/D595 12 52
                    cmd = "01 03 12 52 00 02";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine();
                    fv1 = fv2 = (float)JLMUtlity.Get32BitResult(result.Substring(7, 8));
                    value = fv2.ToString();
                }
                catch (SystemException se)
                {
                    Utils.WriteLog(this.GetType().ToString(), "WD3=" + se.Message);
                }
            }
            return value;
        }

        private string ReadRunStatuLZBX()
        {
            string cmd = "";
            int value = 0;
            string result = "";
            float fv1 = 0.00f, fv2 = 0.00f;
            lock (serialPortInstance)
            {
                try
                {
                    if (!serialPortOpened)
                    {
                        return "";
                    }
                    // 轮子变形
                    cmd = jlmPLCommand.yxZTLZBX + " 00 01";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    JLMLog.Write("=> " + cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine();
                    JLMLog.Write("<= " + result);
                    result = result.Substring(7, 4);
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    fv2 = fv1 = value;
                    if (fv1 > 0)
                    {
                        fv2 = fv1 / 100.0f;
                    }
                }
                catch (SystemException se)
                {

                }
            }
            return fv2.ToString();
        }

        // 电机扭矩
        private string ReadRunStatuDJNJ()
        {
            string cmd = "";
            int value = 0;
            string result = "";
            float fv = 0.0f;
            lock (serialPortInstance)
            {
                try
                {
                    if (!serialPortOpened)
                    {
                        return "";
                    }
                    // 轮子变形
                    cmd = "01 03 10 02 00 01";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    JLMLog.Write("=> " + cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine();
                    JLMLog.Write("<= " + result);
                    result = result.Substring(7, 4);
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    fv = value;
                    if (value > 0)
                    {
                        fv /= 10.0f;
                    }
                }
                catch (SystemException se)
                {

                }
            }
            return fv.ToString();
        }

        // 内温度
        private string ReadRunStatuNWD()
        {
            string cmd = "";
            int value = 0;
            string result = "";
            float fv1 = 0.0f, fv2 = 0.0f;
            lock (serialPortInstance)
            {
                try
                {
                    if (!serialPortOpened)
                    {
                        return "";
                    }
                    // 轮子变形
                    cmd = "01 03 12 56 00 01";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    JLMLog.Write("=> " + cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine();
                    JLMLog.Write("<= " + result);
                    result = result.Substring(7, 4);
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    fv1 = fv2 = value;
                    if (fv2 > 0)
                    {
                        fv2 /= 10.0f;
                    }
                }
                catch (SystemException se)
                {

                }
                return fv2.ToString();
            }
        }

        // 首页读取温度4
        private string ReadRunStatuNWD4()
        {
            string cmd = "";
            string value = "0";
            string result = "";
            float fv1 = 0.0f, fv2 = 0.0f;
            lock (serialPortInstance)
            {
                try
                {
                    if (!serialPortOpened)
                    {
                        return "";
                    }
                    // 读取当前温度4 D596/D597 12 54
                    cmd = "01 03 12 54 00 02";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine();
                    fv1 = fv2 = (float)JLMUtlity.Get32BitResult(result.Substring(7, 8));
                    value = fv2.ToString();
                }
                catch (SystemException se)
                {
                    Utils.WriteLog(this.GetType().ToString(), "NWD4=" + se.Message);
                }
                return value;
            }
        }

        // 电机转速
        private string ReadRunStatuDJZS()
        {
            string cmd = "";
            int value = 0;
            string result = "";
            lock (serialPortInstance)
            {
                try
                {
                    if (!serialPortOpened)
                    {
                        return "";
                    }
                    // 轮子变形
                    cmd = "01 03 10 03 00 02"; /// @20230918 by Fanze
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    JLMLog.Write("=> " + cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine();
                    JLMLog.Write("<= " + result);
                    // @20230919 by Fanze
                    string a = result.Substring(7, 4);
                    string b = result.Substring(11, 4);
                    result = b + a;
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                }
                catch (SystemException se)
                {

                }
            }
            return value.ToString();
        }

        #endregion

        private void WriteProductMC2(string mc)
        {
            if (!serialPortOpened)
            {
                return;
            }

            try
            {
                string mcValue = mc + "&&&&&&&&&&";
                string mcValuePart = mcValue.Substring(0, 2);
                WriteAJLMParam(mcValuePart, false, "01 06 18 16 ");
                mcValuePart = mcValue.Substring(2, 2);
                WriteAJLMParam(mcValuePart, false, "01 06 18 17 ");
                mcValuePart = mcValue.Substring(4, 2);
                WriteAJLMParam(mcValuePart, false, "01 06 18 18 ");
                mcValuePart = mcValue.Substring(6, 2);
                WriteAJLMParam(mcValuePart, false, "01 06 18 19 ");
                mcValuePart = mcValue.Substring(8, 2);
                WriteAJLMParam(mcValuePart, false, "01 06 18 20 ");

                // 将数据写入 18 16/17/18/19/20
            }
            catch (SystemException se)
            {
            }
        }

        private void WriteProductTH2(string th)
        {
            if (!serialPortOpened)
            {
                return;
            }

            try
            {
                string mcValue = th + "&&&&&&&&&&";
                string mcValuePart = mcValue.Substring(0, 2);
                WriteAJLMParam(mcValuePart, false, "01 06 18 20 ");
                mcValuePart = mcValue.Substring(2, 2);
                WriteAJLMParam(mcValuePart, false, "01 06 18 21 ");
                mcValuePart = mcValue.Substring(4, 2);
                WriteAJLMParam(mcValuePart, false, "01 06 18 22 ");
                mcValuePart = mcValue.Substring(6, 2);
                WriteAJLMParam(mcValuePart, false, "01 06 18 23 ");
                mcValuePart = mcValue.Substring(8, 2);
                WriteAJLMParam(mcValuePart, false, "01 06 18 24 ");

                // 将数据写入 18 16/17/18/19/20
            }
            catch (SystemException se)
            {
            }
        }

        private void WriteProductCL2(string cl)
        {
            if (!serialPortOpened)
            {
                return;
            }

            try
            {
                string mcValue = cl + "&&&&&&&&&&";
                string mcValuePart = mcValue.Substring(0, 2);
                WriteAJLMParam(mcValuePart, false, "01 06 18 2a ");
                mcValuePart = mcValue.Substring(2, 2);
                WriteAJLMParam(mcValuePart, false, "01 06 18 2b ");
                mcValuePart = mcValue.Substring(4, 2);
                WriteAJLMParam(mcValuePart, false, "01 06 18 2c ");
                mcValuePart = mcValue.Substring(6, 2);
                WriteAJLMParam(mcValuePart, false, "01 06 18 2d ");
                mcValuePart = mcValue.Substring(8, 2);
                WriteAJLMParam(mcValuePart, false, "01 06 18 2e ");

                // 将数据写入 18 16/17/18/19/20
            }
            catch (SystemException se)
            {
            }
        }

        /// <summary>
        /// 设定测试时间 32b
        /// </summary>
        /// <param name="param"></param>
        /// <param name="paramIsNum"></param>
        /// <param name="configCmd"></param>
        void WriteSJ(string param, bool paramIsNum, string configCmd)
        {
            UInt32 value = 0;
            byte[] arrayValue = null;
            if (param.Length == 0)
            {
                return;
            }
            if (!serialPortOpened)
            {
                return;
            }

            try
            {
                if (paramIsNum) // 参数是数字类型
                {
                    value = Convert.ToUInt32(param); // 先转为数字
                    arrayValue = BitConverter.GetBytes(value); // 转为数组
                    Array.Reverse(arrayValue); // 反转
                }
                else
                {
                    arrayValue = Encoding.ASCII.GetBytes(param); // 直接取ASCII数组
                }

                // 将值格式化为16进制字符串
                StringBuilder builder = new StringBuilder();
                for (int i = 0; i < arrayValue.Length; i++)
                {
                    builder.Append(string.Format("{0:X2} ", arrayValue[i]));
                }
                string hexStringValue = builder.ToString(); // 值的16进制字符串

                // string cmd = configCmd + " " + hexStringValue; // 配置文件中的命令字符串
                string temp = hexStringValue;
                string cmd = "01 06 12 0c " + temp.Substring(0, 5); // 00 00 00 00
                cmd = cmd.ToUpper(); // 替换参数

                // 计算LRC校验，并组合为PLC命令串
                string lrc = Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16);
                if (lrc.Length == 1)
                {
                    lrc = "0" + lrc;
                }
                string cmd2 = ":" + cmd + lrc + "\r\n";

                // 移除空格并转为大写
                cmd2 = cmd2.Replace(" ", "").ToUpper();

                // 发送
                serialPortInstance.Write(cmd2);
                JLMLog.Write("=> " + cmd2);
                Thread.Sleep(20);
                // 接收
                cmd2 = serialPortInstance.ReadLine();
                JLMLog.Write("<= " + cmd2);


                ///
                cmd = "01 06 12 0b " + temp.Substring(6, 5);
                cmd = cmd.ToUpper(); // 替换参数

                // 计算LRC校验，并组合为PLC命令串
                lrc = Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16);
                if (lrc.Length == 1)
                {
                    lrc = "0" + lrc;
                }
                cmd2 = ":" + cmd + lrc + "\r\n";

                // 移除空格并转为大写
                cmd2 = cmd2.Replace(" ", "").ToUpper();

                // 发送
                serialPortInstance.Write(cmd2);
                JLMLog.Write("=> " + cmd2);
                Thread.Sleep(20);
                // 接收
                cmd2 = serialPortInstance.ReadLine();
                JLMLog.Write("<= " + cmd2);
            }
            catch (SystemException se)
            {
            }
        }

        /// <summary>
        /// 设置障碍次数 
        /// </summary>
        /// <param name="param"></param>
        /// <param name="paramIsNum"></param>
        /// <param name="configCmd"></param>
        void WriteZACS(string param, bool paramIsNum, string configCmd)
        {
            UInt32 value = 0;
            byte[] arrayValue = null;
            if (param.Length == 0)
            {
                return;
            }
            if (!serialPortOpened)
            {
                return;
            }

            try
            {
                if (paramIsNum) // 参数是数字类型
                {
                    value = Convert.ToUInt32(param); // 先转为数字
                    arrayValue = BitConverter.GetBytes(value); // 转为数组
                    Array.Reverse(arrayValue); // 反转
                }
                else
                {
                    arrayValue = Encoding.ASCII.GetBytes(param); // 直接取ASCII数组
                }

                // 将值格式化为16进制字符串
                StringBuilder builder = new StringBuilder();
                for (int i = 0; i < arrayValue.Length; i++)
                {
                    builder.Append(string.Format("{0:X2} ", arrayValue[i]));
                }
                string hexStringValue = builder.ToString(); // 值的16进制字符串

                // string cmd = configCmd + " " + hexStringValue; // 配置文件中的命令字符串
                string temp = hexStringValue;
                string cmd = "01 06 18 0e " + temp.Substring(0, 5); // 00 00 00 00
                cmd = cmd.ToUpper(); // 替换参数

                // 计算LRC校验，并组合为PLC命令串
                string lrc = Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16);
                if (lrc.Length == 1)
                {
                    lrc = "0" + lrc;
                }
                string cmd2 = ":" + cmd + lrc + "\r\n";

                // 移除空格并转为大写
                cmd2 = cmd2.Replace(" ", "").ToUpper();

                // 发送
                serialPortInstance.Write(cmd2);
                JLMLog.Write("=> " + cmd2);
                Thread.Sleep(20);
                // 接收
                cmd2 = serialPortInstance.ReadLine();
                JLMLog.Write("<= " + cmd2);


                ///
                cmd = "01 06 18 0b " + temp.Substring(6, 5);
                cmd = cmd.ToUpper(); // 替换参数

                // 计算LRC校验，并组合为PLC命令串
                lrc = Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16);
                if (lrc.Length == 1)
                {
                    lrc = "0" + lrc;
                }
                cmd2 = ":" + cmd + lrc + "\r\n";

                // 移除空格并转为大写
                cmd2 = cmd2.Replace(" ", "").ToUpper();

                // 发送
                serialPortInstance.Write(cmd2);
                JLMLog.Write("=> " + cmd2);
                Thread.Sleep(20);
                // 接收
                cmd2 = serialPortInstance.ReadLine();
                JLMLog.Write("<= " + cmd2);
            }
            catch (SystemException se)
            {
            }
        }
        /// <summary>
        /// 设置测试参数 包括产品信息
        /// </summary>
        public void WriteTestParam(JLMProductData data, JLMTestParamData testParam)
        {
            if (!serialPortOpened)
            {
                return;
            }

            lock (serialPortInstance)
            {
                JLMLog.Write("\r\nWriteTestParam Begin\r\n");
                // 设置产品编号
                WriteAJLMParam(data.BH, true, jlmPLCommand.cpSZBH);

                // 设置产品名称            
                WriteProductMC2(data.MC);

                // 设置产品图号            
                WriteProductTH2(data.TH);

                // 设置产品材料
                WriteProductCL2(data.CL);

                // 设置产品外径
                WriteAJLMParam(data.WJ, true, jlmPLCommand.cpSZWJ);

                // 设置产品硬度
                WriteAJLMParam(data.YD, true, jlmPLCommand.cpSZYD);

                if (testParam.configZXC)
                {
                    // 设置测试总行程
                    //WriteAJLMParam2(testParam.ZXC, true, jlmPLCommand.csSZZXC);
                    Write32BitParam(testParam.ZXC, "12 0a");
                }
                else
                {
                    Write32BitParam(testParam.SJ, "12 0c");
                    // 设置测试时间
                    //WriteAJLMParam(testParam.SJ, true, jlmPLCommand.csSZSJ);
                    //WriteSJ(testParam.SJ, true, jlmPLCommand.csSZSJ);
                }

                // 设置障碍次数
                Write32BitParam(testParam.ZACS, "18 0e");
                //WriteAJLMParam(testParam.ZACS, true, jlmPLCommand.csSZZACS);
                //WriteZACS(testParam.ZACS, true, jlmPLCommand.csSZZACS); /// @2024.03.16 改为32b

                // 设置测试负载
                //WriteAJLMParam(testParam.CSFZ, true, jlmPLCommand.csSZCSFZ);
                Write32BitParam(testParam.CSFZ, "12 10");

                // 设置测试速度
                WriteAJLMParam(testParam.CSSD, true, jlmPLCommand.csSZCSSD);

                // 设置障碍物高度
                WriteAJLMParam(testParam.ZAWGD, true, jlmPLCommand.csSZZWWGD);

                JLMLog.Write("WriteTestParam End\r\n");
            }
        }

        public void WriteTestModeParam(JLMTestModeData modeData)
        {
            if (!serialPortOpened)
            {
                return;
            }

            lock (serialPortInstance)
            {
                // 读取正转时间参数
                WriteAJLMParam(modeData.ZZ, true, jlmPLCommand.yxSZZZSJ);

                // 设置反转时间参数
                WriteAJLMParam(modeData.FZ, true, jlmPLCommand.yxSZFZSJ);

                // 设置间隙停顿
                WriteAJLMParam(modeData.JXTD, true, jlmPLCommand.yxSZTDSJ);
            }
        }

        public void ReadTestModeParam(JLMTestModeData modeData)
        {
            lock (serialPortInstance)
            {
                modeData.ZZ = ReadTestModeParamZZSJ(false);
                modeData.FZ = ReadTestModeParamFZSJ(false);
                modeData.JXTD = ReadTestModeParamTDSJ(false);
            }
        }

        public void ReadJLMData(JLMDataExchange exchanger)
        {
            try
            {
                // 读取产品名称
                exchanger.MC = ReadProductMC().Replace("&", "").Trim().Replace(" ", "");

                // 读取产品图号
                exchanger.TH = ReadProductTH().Replace("&", "").Trim().Replace(" ", "");

                // 读取产品材料
                exchanger.CL = ReadProductCL().Replace("&", "").Trim().Replace(" ", "");

                // 读取产品编号
                exchanger.BH = ReadProductBH();

                // 读取产品外径
                exchanger.WJ = ReadProductWJ();

                // 读取产品硬度
                exchanger.YD = ReadProductYD();

                exchanger.ZXC = ReadTestParamZXC();
                exchanger.SJ = ReadTestParamSJ();
                exchanger.ZACS = ReadTestParamZACS();
                exchanger.CSFZ = ReadTestParamCSFZ();
                exchanger.CSSD = ReadTestParamCSSD();
                exchanger.ZAWGD = ReadTestParamZWWGD();

                exchanger.ZZ = ReadTestModeParamZZSJ();
                exchanger.FZ = ReadTestModeParamFZSJ();
                exchanger.JXTD = ReadTestModeParamTDSJ();

                exchanger.JQZT = ReadRunStatusYXZT();
                exchanger.XC = ReadRunStatusDQXC();
                exchanger.PJSD = ReadRunStatuPJSD();
                exchanger.XZSD = ReadRunStatuXZSD();
                int CSSJ = ReadRunStatuYCSJ2();
                if (CSSJ > 0)
                {
                    exchanger.maxCSSJ = CSSJ;
                }
                exchanger.CSSJ = CSSJ.ToString();
                exchanger.PZCS = ReadRunStatuPZCS2();
                exchanger.WD = ReadRunStatuDQWD();
                exchanger.LZBX = ReadRunStatuLZBX();

                exchanger.DJNJ = ReadRunStatuDJNJ();
                exchanger.NWD = ReadRunStatuNWD();
                exchanger.DJZS = ReadRunStatuDJZS();

                exchanger.WD3 = ReadRunStatuDQWD3();
                exchanger.NWD4 = ReadRunStatuNWD4();
                //Utils.WriteLog(this.GetType().ToString(), "ReadJLMData" + JsonConvert.SerializeObject(exchanger));
            }
            catch (Exception ex)
            {
                MessageBox.Show($"ReadJLMData->" + ex.Message);
            }
        }

        public void ReadRunStatus(JLMDataExchange exchanger)
        {
            int CSSJ = 0;
            exchanger.JQZT = ReadRunStatusYXZT();
            exchanger.XC = ReadRunStatusDQXC();
            exchanger.PJSD = ReadRunStatuPJSD();
            exchanger.XZSD = ReadRunStatuXZSD();
            CSSJ = ReadRunStatuYCSJ2();
            if (CSSJ != 0)
            {
                exchanger.maxCSSJ = CSSJ;
            }
            exchanger.CSSJ = CSSJ.ToString();
            exchanger.PZCS = ReadRunStatuPZCS2();
            exchanger.WD = ReadRunStatuDQWD();
            exchanger.LZBX = ReadRunStatuLZBX();

            exchanger.DJNJ = ReadRunStatuDJNJ();
            exchanger.NWD = ReadRunStatuNWD();
            exchanger.DJZS = ReadRunStatuDJZS();

            exchanger.WD3 = ReadRunStatuDQWD3();
            exchanger.NWD4 = ReadRunStatuNWD4();

            //ReadSettingYL(exchanger);
        }

        public void ReadSettingYL(JLMDataExchange exchanger)
        {
            try
            {
                string cmd = "", result = "";
                float fv1 = 0, fv2 = 0;
                // 读取设置压力值1
                cmd = "01 03 12 18 00 02";
                cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                cmd = cmd.Replace(" ", "").ToUpper();
                // 发送
                serialPortInstance.Write(cmd);
                Thread.Sleep(20);
                // 接收
                result = serialPortInstance.ReadLine();
                fv1 = fv2 = (float)JLMUtlity.Get32BitResult(result.Substring(7, 8));
                exchanger.SZYL1 = fv2.ToString();

                #region 20241102 源 读取设置压力234
                // 读取设置压力值2
                cmd = "01 03 11 ae 00 02";
                cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                cmd = cmd.Replace(" ", "").ToUpper();
                // 发送
                serialPortInstance.Write(cmd);
                Thread.Sleep(20);
                // 接收
                result = serialPortInstance.ReadLine();
                fv1 = fv2 = (float)JLMUtlity.Get32BitResult(result.Substring(7, 8));
                exchanger.SZYL2 = fv2.ToString();

                // 读取设置压力值3
                cmd = "01 03 11 b0 00 02";
                cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                cmd = cmd.Replace(" ", "").ToUpper();
                // 发送
                serialPortInstance.Write(cmd);
                Thread.Sleep(20);
                // 接收
                result = serialPortInstance.ReadLine();
                fv1 = fv2 = (float)JLMUtlity.Get32BitResult(result.Substring(7, 8));
                exchanger.SZYL3 = fv2.ToString();

                // 读取设置压力值4
                cmd = "01 03 11 b2 00 02";
                cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                cmd = cmd.Replace(" ", "").ToUpper();
                // 发送
                serialPortInstance.Write(cmd);
                Thread.Sleep(20);
                // 接收
                result = serialPortInstance.ReadLine();
                fv1 = fv2 = (float)JLMUtlity.Get32BitResult(result.Substring(7, 8));
                exchanger.SZYL4 = fv2.ToString();
                #endregion
            }
            catch (Exception ex)
            {
                Utils.WriteLog(this.GetType().ToString(), ex.Message);
            }
        }

        #region 控制按钮接通
        // 控制按钮
        public void ControlBtn(string btnCmd, bool on)
        {
            lock (serialPortInstance)
            {
                try
                {
                    string cmd = "";
                    if (!serialPortOpened)
                    {
                        return;
                    }

                    // 接通保存继电器
                    cmd = btnCmd;

                    // 计算LRC校验，并组合为PLC命令串
                    if (on)
                    {
                        cmd = cmd + " FF 00";
                    }
                    else
                    {
                        cmd = cmd + " 00 00";
                    }

                    string lrcCode = Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16);
                    if (lrcCode.Length == 1)
                    {
                        lrcCode = "0" + lrcCode;
                    }
                    string cmd2 = ":" + cmd + lrcCode + "\r\n";
                    // 移除空格并转为大写
                    cmd2 = cmd2.Replace(" ", "").ToUpper();

                    // 发送
                    serialPortInstance.Write(cmd2);
                    JLMLog.Write("-> " + cmd2);
                    Thread.Sleep(20);
                    // 接收
                    cmd2 = serialPortInstance.ReadLine();
                    JLMLog.Write("<- " + cmd2);
                }
                catch (SystemException se)
                {

                }
            }
        }
        #endregion

        #region 系统参数设置
        public void ReadXTCSSZParam(JLMSystemSetParam param)
        {
            lock (serialPortInstance)
            {
                try
                {
                    string cmd = "", result = "";
                    int value = 0;
                    float fv1 = 0.0f, fv2 = 0.0f;
                    // 写滚轮外径            
                    cmd = "01 03 12 08" + " 00 01";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 4);
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    param.GLWJ = value.ToString();

                    // 读波箱比例            
                    cmd = jlmPLCommand.xtcsDQBXBL + " 00 01";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 4);
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    param.BXBL = value.ToString();

                    // 读障碍条个数           
                    cmd = jlmPLCommand.xtcsDQZATGS + " 00 01";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 4);
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    param.ZATGS = value.ToString();

                    // 读障感应板块数           
                    cmd = jlmPLCommand.xtcsDQGYBKS + " 00 01";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 4);
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    param.GYBKS = value.ToString();

                    // 读压力           
                    cmd = jlmPLCommand.xtcsDQYL + " 00 01";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 4);
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    fv1 = value;
                    if (value > 0)
                    {
                        fv1 /= 10.0f;
                    }
                    param.DQYL = fv1.ToString();

                    // 外温度1 D590=10 b0              
                    cmd = "01 03 10 b0 00 02";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    result = serialPortInstance.ReadLine();
                    //Utils.WriteLog(this.GetType().ToString(), "DQWWD->" + result);
                    // 接收
                    fv1 = fv2 = (float)JLMUtlity.Get32BitResult(result.Substring(7, 8));
                    param.DQWWD = fv1.ToString();

                    // 外温度偏差1  D506 11 fa          
                    cmd = "01 03 11 fa 00 02";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    //result = serialPortInstance.ReadLine(); result = result.Substring(7, 4);
                    //value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    //value /= 10;
                    result = serialPortInstance.ReadLine();
                    //Utils.WriteLog(this.GetType().ToString(), "WWDPC->" + result);
                    fv1 = fv2 = (float)JLMUtlity.Get32BitResult(result.Substring(7, 8));
                    param.WWDPC = fv1.ToString();

                    // 读取内温度2   D598=11 14      
                    cmd = "01 03 11 14 00 02";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine();
                    //Utils.WriteLog(this.GetType().ToString(), "NWD->" + result);
                    fv1 = fv2 = (float)JLMUtlity.Get32BitResult(result.Substring(7, 8));
                    param.NWD = fv2.ToString();

                    // 读取内温度偏差2   D508 11 fc        
                    cmd = "01 03 11 fc 00 02";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    //result = serialPortInstance.ReadLine(); result = result.Substring(7, 4);
                    //value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    //value /= 10;
                    result = serialPortInstance.ReadLine();
                    //Utils.WriteLog(this.GetType().ToString(), "NWDPC->" + result);
                    fv1 = fv2 = (float)JLMUtlity.Get32BitResult(result.Substring(7, 8));
                    param.NWDPC = fv1.ToString();

                    #region 20241101源
                    // 外温度3 D460,D461=11 cc              
                    cmd = "01 03 11 cc 00 02";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine();
                    //Utils.WriteLog(this.GetType().ToString(), "DQWWD3->" + result);
                    fv1 = fv2 = (float)JLMUtlity.Get32BitResult(result.Substring(7, 8));
                    param.DQWWD3 = fv1.ToString();

                    // 外温度偏差3 D464,D465 11 d0           
                    cmd = "01 03 11 D0 00 02";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    //result = serialPortInstance.ReadLine(); result = result.Substring(7, 4);
                    //value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    //value /= 10;
                    result = serialPortInstance.ReadLine();
                    //Utils.WriteLog(this.GetType().ToString(), "WWDPC3->" + result);
                    fv1 = fv2 = (float)JLMUtlity.Get32BitResult(result.Substring(7, 8));
                    param.WWDPC3 = fv1.ToString();

                    // 读取内温度4   D462,D463=11 ce      
                    cmd = "01 03 11 ce 00 02";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine();
                    fv1 = fv2 = (float)JLMUtlity.Get32BitResult(result.Substring(7, 8));
                    param.NWD4 = fv2.ToString();

                    // 读取内温度偏差4 D466,D467 11 d2          
                    cmd = "01 03 11 d2 00 02";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    //result = serialPortInstance.ReadLine(); result = result.Substring(7, 4);
                    //value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    //value /= 10;
                    result = serialPortInstance.ReadLine();
                    //Utils.WriteLog(this.GetType().ToString(), "NWDPC4->" + result);
                    fv1 = fv2 = (float)JLMUtlity.Get32BitResult(result.Substring(7, 8));
                    param.NWDPC4 = fv1.ToString();
                    #endregion
                }
                catch (SystemException se)
                {

                }

            }

        }

        public void WriteXTCSSZParam(JLMSystemSetParam param)
        {
            lock (serialPortInstance)
            {
                ushort value = 0;
                byte[] arrayValue = null;
                try
                {
                    value = Convert.ToUInt16(param.GLWJ); // 先转为数字
                    arrayValue = BitConverter.GetBytes(value); // 转为数组
                    Array.Reverse(arrayValue); // 反转

                    // 将值格式化为16进制字符串
                    StringBuilder builder = new StringBuilder();
                    for (int i = 0; i < arrayValue.Length; i++)
                    {
                        builder.Append(string.Format("{0:X2} ", arrayValue[i]));
                    }
                    string hexStringValue = builder.ToString(); // 值的16进制字符串

                    string cmd = "01 06 12 08" + " " + hexStringValue; // 配置文件中的命令字符串
                    cmd = cmd.ToUpper(); // 替换参数

                    // 计算LRC校验，并组合为PLC命令串

                    //string cmd2 = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    string lrcCode = Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16);
                    if (lrcCode.Length == 1)
                    {
                        lrcCode = "0" + lrcCode;
                    }
                    string cmd2 = ":" + cmd + lrcCode + "\r\n";
                    // 移除空格并转为大写
                    cmd2 = cmd2.Replace(" ", "").ToUpper();

                    // 发送
                    serialPortInstance.Write(cmd2);
                    Thread.Sleep(20);
                    // 接收
                    cmd2 = serialPortInstance.ReadLine();
                }
                catch (SystemException se)
                {
                }

                try
                {
                    value = Convert.ToUInt16(param.BXBL); // 先转为数字
                    arrayValue = BitConverter.GetBytes(value); // 转为数组
                    Array.Reverse(arrayValue); // 反转

                    // 将值格式化为16进制字符串
                    StringBuilder builder = new StringBuilder();
                    for (int i = 0; i < arrayValue.Length; i++)
                    {
                        builder.Append(string.Format("{0:X2} ", arrayValue[i]));
                    }
                    string hexStringValue = builder.ToString(); // 值的16进制字符串

                    string cmd = jlmPLCommand.xtcsSZBXBL + " " + hexStringValue; // 配置文件中的命令字符串
                    cmd = cmd.ToUpper(); // 替换参数

                    // 计算LRC校验，并组合为PLC命令串
                    //string cmd2 = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    string lrcCode = Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16);
                    if (lrcCode.Length == 1)
                    {
                        lrcCode = "0" + lrcCode;
                    }
                    string cmd2 = ":" + cmd + lrcCode + "\r\n";

                    // 移除空格并转为大写
                    cmd2 = cmd2.Replace(" ", "").ToUpper();

                    // 发送
                    serialPortInstance.Write(cmd2);
                    Thread.Sleep(20);
                    // 接收
                    cmd2 = serialPortInstance.ReadLine();
                }
                catch (SystemException se)
                {
                }

                try
                {
                    value = Convert.ToUInt16(param.ZATGS); // 先转为数字
                    arrayValue = BitConverter.GetBytes(value); // 转为数组
                    Array.Reverse(arrayValue); // 反转

                    // 将值格式化为16进制字符串
                    StringBuilder builder = new StringBuilder();
                    for (int i = 0; i < arrayValue.Length; i++)
                    {
                        builder.Append(string.Format("{0:X2} ", arrayValue[i]));
                    }
                    string hexStringValue = builder.ToString(); // 值的16进制字符串

                    string cmd = jlmPLCommand.xtcsSZZATGS + " " + hexStringValue; // 配置文件中的命令字符串
                    cmd = cmd.ToUpper(); // 替换参数

                    // 计算LRC校验，并组合为PLC命令串
                    // string cmd2 = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    string lrcCode = Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16);
                    if (lrcCode.Length == 1)
                    {
                        lrcCode = "0" + lrcCode;
                    }
                    string cmd2 = ":" + cmd + lrcCode + "\r\n";

                    // 移除空格并转为大写
                    cmd2 = cmd2.Replace(" ", "").ToUpper();

                    // 发送
                    serialPortInstance.Write(cmd2);
                    Thread.Sleep(20);
                    // 接收
                    cmd2 = serialPortInstance.ReadLine();
                }
                catch (SystemException se)
                {
                }

                try
                {
                    value = Convert.ToUInt16(param.GYBKS); // 先转为数字
                    arrayValue = BitConverter.GetBytes(value); // 转为数组
                    Array.Reverse(arrayValue); // 反转

                    // 将值格式化为16进制字符串
                    StringBuilder builder = new StringBuilder();
                    for (int i = 0; i < arrayValue.Length; i++)
                    {
                        builder.Append(string.Format("{0:X2} ", arrayValue[i]));
                    }
                    string hexStringValue = builder.ToString(); // 值的16进制字符串

                    string cmd = jlmPLCommand.xtcsSZGYBKS + " " + hexStringValue; // 配置文件中的命令字符串
                    cmd = cmd.ToUpper(); // 替换参数

                    // 计算LRC校验，并组合为PLC命令串
                    //string cmd2 = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    string lrcCode = Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16);
                    if (lrcCode.Length == 1)
                    {
                        lrcCode = "0" + lrcCode;
                    }
                    string cmd2 = ":" + cmd + lrcCode + "\r\n";

                    // 移除空格并转为大写
                    cmd2 = cmd2.Replace(" ", "").ToUpper();

                    // 发送
                    serialPortInstance.Write(cmd2);
                    Thread.Sleep(20);
                    // 接收
                    cmd2 = serialPortInstance.ReadLine();
                }
                catch (SystemException se)
                {
                }

                try
                {
                    value = Convert.ToUInt16(param.DQYL); // 先转为数字
                    arrayValue = BitConverter.GetBytes(value); // 转为数组
                    Array.Reverse(arrayValue); // 反转

                    // 将值格式化为16进制字符串
                    StringBuilder builder = new StringBuilder();
                    for (int i = 0; i < arrayValue.Length; i++)
                    {
                        builder.Append(string.Format("{0:X2} ", arrayValue[i]));
                    }
                    string hexStringValue = builder.ToString(); // 值的16进制字符串

                    string cmd = jlmPLCommand.xtcsSZYL + " " + hexStringValue; // 配置文件中的命令字符串
                    cmd = cmd.ToUpper(); // 替换参数

                    // 计算LRC校验，并组合为PLC命令串
                    //string cmd2 = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    string lrcCode = Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16);
                    if (lrcCode.Length == 1)
                    {
                        lrcCode = "0" + lrcCode;
                    }
                    string cmd2 = ":" + cmd + lrcCode + "\r\n";

                    // 移除空格并转为大写
                    cmd2 = cmd2.Replace(" ", "").ToUpper();

                    // 发送
                    serialPortInstance.Write(cmd2);
                    Thread.Sleep(20);
                    // 接收
                    cmd2 = serialPortInstance.ReadLine();
                }
                catch (SystemException se)
                {
                }

                try
                {
                    value = Convert.ToUInt16(param.PCWD); // 先转为数字
                    arrayValue = BitConverter.GetBytes(value); // 转为数组
                    Array.Reverse(arrayValue); // 反转

                    // 将值格式化为16进制字符串
                    StringBuilder builder = new StringBuilder();
                    for (int i = 0; i < arrayValue.Length; i++)
                    {
                        builder.Append(string.Format("{0:X2} ", arrayValue[i]));
                    }
                    string hexStringValue = builder.ToString(); // 值的16进制字符串

                    string cmd = jlmPLCommand.xtcsSZPCWD + " " + hexStringValue; // 配置文件中的命令字符串
                    cmd = cmd.ToUpper(); // 替换参数

                    // 计算LRC校验，并组合为PLC命令串
                    //string cmd2 = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    string lrcCode = Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16);
                    if (lrcCode.Length == 1)
                    {
                        lrcCode = "0" + lrcCode;
                    }
                    string cmd2 = ":" + cmd + lrcCode + "\r\n";

                    // 移除空格并转为大写
                    cmd2 = cmd2.Replace(" ", "").ToUpper();

                    // 发送
                    serialPortInstance.Write(cmd2);
                    Thread.Sleep(20);
                    // 接收
                    cmd2 = serialPortInstance.ReadLine();
                }
                catch (SystemException se)
                {
                }

                try
                {

                    // 外温度偏差1
                    if (!string.IsNullOrEmpty(param.WWDPC))
                    {
                        string Address = "11 fa";
                        Write32BitParam(param.WWDPC, Address);
                    }
                    /*
                    value = Convert.ToUInt16(param.WWDPC); // 先转为数字
                    value *= 10;
                    arrayValue = BitConverter.GetBytes(value); // 转为数组
                    Array.Reverse(arrayValue); // 反转

                    // 将值格式化为16进制字符串
                    StringBuilder builder2 = new StringBuilder();
                    for (int i = 0; i < arrayValue.Length; i++)
                    {
                        builder2.Append(string.Format("{0:X2} ", arrayValue[i]));
                    }
                    string hexStringValue2 = builder2.ToString(); // 值的16进制字符串

                    string cmd = "01 06 11 fc " + hexStringValue2; // 配置文件中的命令字符串
                    cmd = cmd.ToUpper();

                    // 计算LRC校验，并组合为PLC命令串
                    // string cmd2 = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    string lrcCode = Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16);
                    if (lrcCode.Length == 1)
                    {
                        lrcCode = "0" + lrcCode;
                    }
                    string cmd2 = ":" + cmd + lrcCode + "\r\n";

                    // 移除空格并转为大写
                    cmd2 = cmd2.Replace(" ", "").ToUpper();

                    // 发送
                    serialPortInstance.Write(cmd2);
                    Thread.Sleep(20);
                    // 接收
                    cmd2 = serialPortInstance.ReadLine();
                    */

                    // 内温度偏差2
                    if (!string.IsNullOrEmpty(param.NWDPC))
                    {
                        string Address = "11 fc";
                        Write32BitParam(param.NWDPC, Address);
                    }
                    /*
                    value = Convert.ToUInt16(param.NWDPC); // 先转为数字
                    value *= 10;
                    arrayValue = BitConverter.GetBytes(value); // 转为数组
                    Array.Reverse(arrayValue); // 反转

                    // 将值格式化为16进制字符串
                    StringBuilder builder4 = new StringBuilder();
                    for (int i = 0; i < arrayValue.Length; i++)
                    {
                        builder4.Append(string.Format("{0:X2} ", arrayValue[i]));
                    }
                    hexStringValue2 = builder4.ToString(); // 值的16进制字符串

                    cmd = "01 06 11 FA " + hexStringValue2; // 配置文件中的命令字符串
                    cmd = cmd.ToUpper();

                    // 计算LRC校验，并组合为PLC命令串
                    // cmd2 = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    lrcCode = Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16);
                    if (lrcCode.Length == 1)
                    {
                        lrcCode = "0" + lrcCode;
                    }
                    cmd2 = ":" + cmd + lrcCode + "\r\n";


                    // 移除空格并转为大写
                    cmd2 = cmd2.Replace(" ", "").ToUpper();

                    // 发送
                    serialPortInstance.Write(cmd2);
                    Thread.Sleep(20);
                    // 接收
                    cmd2 = serialPortInstance.ReadLine();
                    */
                }
                catch (SystemException se)
                {

                }

                #region 20241101源
                try
                {
                    // 外温度偏差3
                    if (!string.IsNullOrEmpty(param.WWDPC3))
                    {
                        string Address = "11 d0";
                        Write32BitParam(param.WWDPC3, Address);
                    }
                    /*
                    value = Convert.ToUInt16(param.WWDPC3); // 先转为数字
                    value *= 10;
                    arrayValue = BitConverter.GetBytes(value); // 转为数组
                    Array.Reverse(arrayValue); // 反转

                    // 将值格式化为16进制字符串
                    StringBuilder builder2 = new StringBuilder();
                    for (int i = 0; i < arrayValue.Length; i++)
                    {
                        builder2.Append(string.Format("{0:X2} ", arrayValue[i]));
                    }
                    string hexStringValue2 = builder2.ToString(); // 值的16进制字符串

                    string cmd = "01 06 11 d0 " + hexStringValue2; // 配置文件中的命令字符串
                    cmd = cmd.ToUpper();

                    // 计算LRC校验，并组合为PLC命令串
                    // string cmd2 = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    string lrcCode = Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16);
                    if (lrcCode.Length == 1)
                    {
                        lrcCode = "0" + lrcCode;
                    }
                    string cmd2 = ":" + cmd + lrcCode + "\r\n";

                    // 移除空格并转为大写
                    cmd2 = cmd2.Replace(" ", "").ToUpper();

                    // 发送
                    serialPortInstance.Write(cmd2);
                    Thread.Sleep(20);
                    // 接收
                    cmd2 = serialPortInstance.ReadLine();
                    */

                    // 内温度偏差4
                    if (!string.IsNullOrEmpty(param.NWDPC4))
                    {
                        string Address = "11 d2";
                        Write32BitParam(param.NWDPC4, Address);
                    }
                    /*
                    value = Convert.ToUInt16(param.NWDPC4); // 先转为数字
                    value *= 10;
                    arrayValue = BitConverter.GetBytes(value); // 转为数组
                    Array.Reverse(arrayValue); // 反转

                    // 将值格式化为16进制字符串
                    StringBuilder builder4 = new StringBuilder();
                    for (int i = 0; i < arrayValue.Length; i++)
                    {
                        builder4.Append(string.Format("{0:X2} ", arrayValue[i]));
                    }
                    hexStringValue2 = builder4.ToString(); // 值的16进制字符串

                    cmd = "01 06 11 d2 " + hexStringValue2; // 配置文件中的命令字符串
                    cmd = cmd.ToUpper();

                    // 计算LRC校验，并组合为PLC命令串
                    // cmd2 = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    lrcCode = Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16);
                    if (lrcCode.Length == 1)
                    {
                        lrcCode = "0" + lrcCode;
                    }
                    cmd2 = ":" + cmd + lrcCode + "\r\n";


                    // 移除空格并转为大写
                    cmd2 = cmd2.Replace(" ", "").ToUpper();

                    // 发送
                    serialPortInstance.Write(cmd2);
                    Thread.Sleep(20);
                    // 接收
                    cmd2 = serialPortInstance.ReadLine();
                    */
                }
                catch (SystemException se)
                {

                }
                #endregion
            }
        }

        #endregion

        public void ReadBLCSSZParam(JLMBLSetParam param)
        {
            lock (serialPortInstance)
            {
                try
                {
                    string cmd = "", result = "";
                    int value = 0;
                    float fv = 0.0f;
                    cmd = jlmPLCommand.xtcsDQYL1 + " 00 02";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 8);
                    //value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    value = Convert.ToInt32(JLMUtlity.Get32BitResult(result));
                    param.BL1 = value.ToString();


                    cmd = jlmPLCommand.xtcsDQYL2 + " 00 02";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 8);
                    //value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    value = Convert.ToInt32(JLMUtlity.Get32BitResult(result));
                    param.BL2 = value.ToString();


                    cmd = jlmPLCommand.xtcsDQYL3 + " 00 02";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 8);
                    //value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    value = Convert.ToInt32(JLMUtlity.Get32BitResult(result));
                    param.BL3 = value.ToString();

                    cmd = jlmPLCommand.xtcsDQYL4 + " 00 02";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 8);
                    //value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    value = Convert.ToInt32(JLMUtlity.Get32BitResult(result));
                    param.BL4 = value.ToString();

                    cmd = jlmPLCommand.xtcsDQYL5 + " 00 02";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 8);
                    //value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    value = Convert.ToInt32(JLMUtlity.Get32BitResult(result));
                    fv = value;
                    param.BL5 = value.ToString();

                    cmd = jlmPLCommand.xtcsDQYL6 + " 00 02";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 8);
                    //value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    value = Convert.ToInt32(JLMUtlity.Get32BitResult(result));
                    param.BL6 = value.ToString();

                    cmd = jlmPLCommand.xtcsDQYL7 + " 00 02";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 8);
                    //value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    value = Convert.ToInt32(JLMUtlity.Get32BitResult(result));
                    fv = value;
                    param.BL7 = value.ToString();

                    cmd = jlmPLCommand.xtcsDQYL8 + " 00 02";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 8);
                    //value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    value = Convert.ToInt32(JLMUtlity.Get32BitResult(result));
                    fv = value;
                    param.BL8 = value.ToString();

                    cmd = jlmPLCommand.xtcsDQYL9 + " 00 02";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 8);
                    //value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    value = Convert.ToInt32(JLMUtlity.Get32BitResult(result));
                    param.BL9 = value.ToString();

                    cmd = jlmPLCommand.xtcsDQYL10 + " 00 02";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 8);
                    //value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    value = Convert.ToInt32(JLMUtlity.Get32BitResult(result));
                    param.BL10 = value.ToString();
                }
                catch (SystemException se)
                {
                }
            }
        }

        public void ReadIndexBLCSSZParam2(JLMBLSetParam param)
        {
            lock (serialPortInstance)
            {
                try
                {
                    string cmd = "", result = "";
                    int value = 0;
                    cmd = "01 03 11 b8 00 02"; //D440/D441
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 8);
                    value = Convert.ToInt32(JLMUtlity.Get32BitResult(result));
                    param.BL1 = value.ToString();


                    cmd = "01 03 11 ba 00 02"; //D442/D443
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 8);
                    value = Convert.ToInt32(JLMUtlity.Get32BitResult(result));
                    param.BL2 = value.ToString();


                    cmd = "01 03 11 bc 00 02"; //D444/D445
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 8);
                    value = Convert.ToInt32(JLMUtlity.Get32BitResult(result));
                    param.BL3 = value.ToString();

                    cmd = "01 03 11 be 00 02"; //D446/D447
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 8);
                    value = Convert.ToInt32(JLMUtlity.Get32BitResult(result));
                    param.BL4 = value.ToString();

                    cmd = "01 03 11 c0 00 02"; //D448/D449
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 8);
                    value = Convert.ToInt32(JLMUtlity.Get32BitResult(result));
                    param.BL5 = value.ToString();

                    cmd = "01 03 11 c2 00 02"; //D450/D451
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 8);
                    value = Convert.ToInt32(JLMUtlity.Get32BitResult(result));
                    param.BL6 = value.ToString();

                    cmd = "01 03 11 c4 00 02"; //D452/D453
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 8);
                    value = Convert.ToInt32(JLMUtlity.Get32BitResult(result));
                    param.BL7 = value.ToString();

                    cmd = "01 03 11 c6 00 02"; //D454/D455
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 8);
                    value = Convert.ToInt32(JLMUtlity.Get32BitResult(result));
                    param.BL8 = value.ToString();

                    cmd = "01 03 11 c8 00 02"; //D456/D457
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 8);
                    value = Convert.ToInt32(JLMUtlity.Get32BitResult(result));
                    param.BL9 = value.ToString();

                    cmd = "01 03 11 ca 00 02"; //D458/D459
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 8);
                    value = Convert.ToInt32(JLMUtlity.Get32BitResult(result));
                    param.BL10 = value.ToString();
                }
                catch (SystemException se)
                {
                }
            }
        }

        public void WriteBLCSSZParam(JLMBLSetParam param)
        {
            ushort value = 0;
            byte[] arrayValue = null;
            lock (serialPortInstance)
            {
                try
                {
                    /*
                    value = Convert.ToUInt16(param.BL1); // 先转为数字
                    arrayValue = BitConverter.GetBytes(value); // 转为数组
                    Array.Reverse(arrayValue); // 反转

                    // 将值格式化为16进制字符串
                    StringBuilder builder = new StringBuilder();
                    for (int i = 0; i < arrayValue.Length; i++)
                    {
                        builder.Append(string.Format("{0:X2} ", arrayValue[i]));
                    }
                    string hexStringValue = builder.ToString(); // 值的16进制字符串

                    string cmd = jlmPLCommand.xtcsSZYL1 + " " + hexStringValue; // 配置文件中的命令字符串
                    cmd = cmd.ToUpper(); // 替换参数

                    // 计算LRC校验，并组合为PLC命令串
                    //string cmd2 = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    string lrcCode = Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16);
                    if (lrcCode.Length == 1)
                    {
                        lrcCode = "0" + lrcCode;
                    }
                    string cmd2 = ":" + cmd + lrcCode + "\r\n";

                    // 移除空格并转为大写
                    cmd2 = cmd2.Replace(" ", "").ToUpper();

                    // 发送
                    serialPortInstance.Write(cmd2);
                    Thread.Sleep(20);
                    // 接收
                    cmd2 = serialPortInstance.ReadLine();
                    */
                    Write32BitParam(param.BL1, "12 26");
                }
                catch (SystemException se)
                {
                }

                try
                {
                    /*
                    value = Convert.ToUInt16(param.BL2); // 先转为数字
                    arrayValue = BitConverter.GetBytes(value); // 转为数组
                    Array.Reverse(arrayValue); // 反转

                    // 将值格式化为16进制字符串
                    StringBuilder builder = new StringBuilder();
                    for (int i = 0; i < arrayValue.Length; i++)
                    {
                        builder.Append(string.Format("{0:X2} ", arrayValue[i]));
                    }
                    string hexStringValue = builder.ToString(); // 值的16进制字符串

                    string cmd = jlmPLCommand.xtcsSZYL2 + " " + hexStringValue; // 配置文件中的命令字符串
                    cmd = cmd.ToUpper(); // 替换参数

                    // 计算LRC校验，并组合为PLC命令串
                    //string cmd2 = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    string lrcCode = Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16);
                    if (lrcCode.Length == 1)
                    {
                        lrcCode = "0" + lrcCode;
                    }
                    string cmd2 = ":" + cmd + lrcCode + "\r\n";

                    // 移除空格并转为大写
                    cmd2 = cmd2.Replace(" ", "").ToUpper();

                    // 发送
                    serialPortInstance.Write(cmd2);
                    Thread.Sleep(20);
                    // 接收
                    cmd2 = serialPortInstance.ReadLine();
                    */
                    Write32BitParam(param.BL2, "12 28");
                }
                catch (SystemException se)
                {
                }


                try
                {
                    /*
                    value = Convert.ToUInt16(param.BL3); // 先转为数字
                    arrayValue = BitConverter.GetBytes(value); // 转为数组
                    Array.Reverse(arrayValue); // 反转

                    // 将值格式化为16进制字符串
                    StringBuilder builder = new StringBuilder();
                    for (int i = 0; i < arrayValue.Length; i++)
                    {
                        builder.Append(string.Format("{0:X2} ", arrayValue[i]));
                    }
                    string hexStringValue = builder.ToString(); // 值的16进制字符串

                    string cmd = jlmPLCommand.xtcsSZYL3 + " " + hexStringValue; // 配置文件中的命令字符串
                    cmd = cmd.ToUpper(); // 替换参数

                    // 计算LRC校验，并组合为PLC命令串
                    //string cmd2 = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    string lrcCode = Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16);
                    if (lrcCode.Length == 1)
                    {
                        lrcCode = "0" + lrcCode;
                    }
                    string cmd2 = ":" + cmd + lrcCode + "\r\n";

                    // 移除空格并转为大写
                    cmd2 = cmd2.Replace(" ", "").ToUpper();

                    // 发送
                    serialPortInstance.Write(cmd2);
                    Thread.Sleep(20);
                    // 接收
                    cmd2 = serialPortInstance.ReadLine();
                    */
                    Write32BitParam(param.BL3, "12 2a");
                }
                catch (SystemException se)
                {
                }

                try
                {
                    /*
                    value = Convert.ToUInt16(param.BL4); // 先转为数字
                    arrayValue = BitConverter.GetBytes(value); // 转为数组
                    Array.Reverse(arrayValue); // 反转

                    // 将值格式化为16进制字符串
                    StringBuilder builder = new StringBuilder();
                    for (int i = 0; i < arrayValue.Length; i++)
                    {
                        builder.Append(string.Format("{0:X2} ", arrayValue[i]));
                    }
                    string hexStringValue = builder.ToString(); // 值的16进制字符串

                    string cmd = jlmPLCommand.xtcsSZYL4 + " " + hexStringValue; // 配置文件中的命令字符串
                    cmd = cmd.ToUpper(); // 替换参数

                    // 计算LRC校验，并组合为PLC命令串
                    //string cmd2 = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    string lrcCode = Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16);
                    if (lrcCode.Length == 1)
                    {
                        lrcCode = "0" + lrcCode;
                    }
                    string cmd2 = ":" + cmd + lrcCode + "\r\n";

                    // 移除空格并转为大写
                    cmd2 = cmd2.Replace(" ", "").ToUpper();

                    // 发送
                    serialPortInstance.Write(cmd2);
                    Thread.Sleep(20);
                    // 接收
                    cmd2 = serialPortInstance.ReadLine();
                    */
                    Write32BitParam(param.BL4, "12 2c");
                }
                catch (SystemException se)
                {
                }

                try
                {
                    /*
                    value = Convert.ToUInt16(param.BL5); // 先转为数字
                    arrayValue = BitConverter.GetBytes(value); // 转为数组
                    Array.Reverse(arrayValue); // 反转

                    // 将值格式化为16进制字符串
                    StringBuilder builder = new StringBuilder();
                    for (int i = 0; i < arrayValue.Length; i++)
                    {
                        builder.Append(string.Format("{0:X2} ", arrayValue[i]));
                    }
                    string hexStringValue = builder.ToString(); // 值的16进制字符串

                    string cmd = jlmPLCommand.xtcsSZYL5 + " " + hexStringValue; // 配置文件中的命令字符串
                    cmd = cmd.ToUpper(); // 替换参数

                    // 计算LRC校验，并组合为PLC命令串
                    //string cmd2 = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    string lrcCode = Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16);
                    if (lrcCode.Length == 1)
                    {
                        lrcCode = "0" + lrcCode;
                    }
                    string cmd2 = ":" + cmd + lrcCode + "\r\n";

                    // 移除空格并转为大写
                    cmd2 = cmd2.Replace(" ", "").ToUpper();

                    // 发送
                    serialPortInstance.Write(cmd2);
                    Thread.Sleep(20);
                    // 接收
                    cmd2 = serialPortInstance.ReadLine();
                    */
                    Write32BitParam(param.BL5, "12 2e");
                }
                catch (SystemException se)
                {
                }

                try
                {
                    /*
                    value = Convert.ToUInt16(param.BL6); // 先转为数字
                    arrayValue = BitConverter.GetBytes(value); // 转为数组
                    Array.Reverse(arrayValue); // 反转

                    // 将值格式化为16进制字符串
                    StringBuilder builder = new StringBuilder();
                    for (int i = 0; i < arrayValue.Length; i++)
                    {
                        builder.Append(string.Format("{0:X2} ", arrayValue[i]));
                    }
                    string hexStringValue = builder.ToString(); // 值的16进制字符串

                    string cmd = jlmPLCommand.xtcsSZYL6 + " " + hexStringValue; // 配置文件中的命令字符串
                    cmd = cmd.ToUpper(); // 替换参数

                    // 计算LRC校验，并组合为PLC命令串
                    // string cmd2 = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    string lrcCode = Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16);
                    if (lrcCode.Length == 1)
                    {
                        lrcCode = "0" + lrcCode;
                    }
                    string cmd2 = ":" + cmd + lrcCode + "\r\n";

                    // 移除空格并转为大写
                    cmd2 = cmd2.Replace(" ", "").ToUpper();

                    // 发送
                    serialPortInstance.Write(cmd2);
                    Thread.Sleep(20);
                    // 接收
                    cmd2 = serialPortInstance.ReadLine();
                    */
                    Write32BitParam(param.BL6, "12 30");
                }
                catch (SystemException se)
                {
                }

                try
                {
                    /*
                    value = Convert.ToUInt16(param.BL7); // 先转为数字
                    arrayValue = BitConverter.GetBytes(value); // 转为数组
                    Array.Reverse(arrayValue); // 反转

                    // 将值格式化为16进制字符串
                    StringBuilder builder = new StringBuilder();
                    for (int i = 0; i < arrayValue.Length; i++)
                    {
                        builder.Append(string.Format("{0:X2} ", arrayValue[i]));
                    }
                    string hexStringValue = builder.ToString(); // 值的16进制字符串

                    string cmd = jlmPLCommand.xtcsSZYL7 + " " + hexStringValue; // 配置文件中的命令字符串
                    cmd = cmd.ToUpper(); // 替换参数

                    // 计算LRC校验，并组合为PLC命令串
                    //string cmd2 = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    string lrcCode = Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16);
                    if (lrcCode.Length == 1)
                    {
                        lrcCode = "0" + lrcCode;
                    }
                    string cmd2 = ":" + cmd + lrcCode + "\r\n";

                    // 移除空格并转为大写
                    cmd2 = cmd2.Replace(" ", "").ToUpper();

                    // 发送
                    serialPortInstance.Write(cmd2);
                    Thread.Sleep(20);
                    // 接收
                    cmd2 = serialPortInstance.ReadLine();
                    */
                    Write32BitParam(param.BL7, "12 32");
                }
                catch (SystemException se)
                {
                }

                try
                {
                    /*
                    value = Convert.ToUInt16(param.BL8); // 先转为数字
                    arrayValue = BitConverter.GetBytes(value); // 转为数组
                    Array.Reverse(arrayValue); // 反转

                    // 将值格式化为16进制字符串
                    StringBuilder builder = new StringBuilder();
                    for (int i = 0; i < arrayValue.Length; i++)
                    {
                        builder.Append(string.Format("{0:X2} ", arrayValue[i]));
                    }
                    string hexStringValue = builder.ToString(); // 值的16进制字符串

                    string cmd = jlmPLCommand.xtcsSZYL8 + " " + hexStringValue; // 配置文件中的命令字符串
                    cmd = cmd.ToUpper(); // 替换参数

                    // 计算LRC校验，并组合为PLC命令串
                    // string cmd2 = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    string lrcCode = Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16);
                    if (lrcCode.Length == 1)
                    {
                        lrcCode = "0" + lrcCode;
                    }
                    string cmd2 = ":" + cmd + lrcCode + "\r\n";

                    // 移除空格并转为大写
                    cmd2 = cmd2.Replace(" ", "").ToUpper();

                    // 发送
                    serialPortInstance.Write(cmd2);
                    Thread.Sleep(20);
                    // 接收
                    cmd2 = serialPortInstance.ReadLine();
                    */
                    Write32BitParam(param.BL8, "12 34");
                }
                catch (SystemException se)
                {
                }

                try
                {
                    /*
                    value = Convert.ToUInt16(param.BL9); // 先转为数字
                    arrayValue = BitConverter.GetBytes(value); // 转为数组
                    Array.Reverse(arrayValue); // 反转

                    // 将值格式化为16进制字符串
                    StringBuilder builder = new StringBuilder();
                    for (int i = 0; i < arrayValue.Length; i++)
                    {
                        builder.Append(string.Format("{0:X2} ", arrayValue[i]));
                    }
                    string hexStringValue = builder.ToString(); // 值的16进制字符串

                    string cmd = jlmPLCommand.xtcsSZYL9 + " " + hexStringValue; // 配置文件中的命令字符串
                    cmd = cmd.ToUpper(); // 替换参数

                    // 计算LRC校验，并组合为PLC命令串
                    //string cmd2 = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    string lrcCode = Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16);
                    if (lrcCode.Length == 1)
                    {
                        lrcCode = "0" + lrcCode;
                    }
                    string cmd2 = ":" + cmd + lrcCode + "\r\n";

                    // 移除空格并转为大写
                    cmd2 = cmd2.Replace(" ", "").ToUpper();

                    // 发送
                    serialPortInstance.Write(cmd2);
                    Thread.Sleep(20);
                    // 接收
                    cmd2 = serialPortInstance.ReadLine();
                    */
                    Write32BitParam(param.BL9, "12 36");
                }
                catch (SystemException se)
                {
                }

                try
                {
                    /*
                    value = Convert.ToUInt16(param.BL10); // 先转为数字
                    arrayValue = BitConverter.GetBytes(value); // 转为数组
                    Array.Reverse(arrayValue); // 反转

                    // 将值格式化为16进制字符串
                    StringBuilder builder = new StringBuilder();
                    for (int i = 0; i < arrayValue.Length; i++)
                    {
                        builder.Append(string.Format("{0:X2} ", arrayValue[i]));
                    }
                    string hexStringValue = builder.ToString(); // 值的16进制字符串

                    string cmd = jlmPLCommand.xtcsSZYL10 + " " + hexStringValue; // 配置文件中的命令字符串
                    cmd = cmd.ToUpper(); // 替换参数

                    // 计算LRC校验，并组合为PLC命令串
                    //string cmd2 = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    string lrcCode = Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16);
                    if (lrcCode.Length == 1)
                    {
                        lrcCode = "0" + lrcCode;
                    }
                    string cmd2 = ":" + cmd + lrcCode + "\r\n";

                    // 移除空格并转为大写
                    cmd2 = cmd2.Replace(" ", "").ToUpper();

                    // 发送
                    serialPortInstance.Write(cmd2);
                    Thread.Sleep(20);
                    // 接收
                    cmd2 = serialPortInstance.ReadLine();
                    */
                    Write32BitParam(param.BL10, "12 38");
                }
                catch (SystemException se)
                {
                }

            }
        }

        public void ReadTSYMParam(JLMTSYMParam param)
        {
            lock (serialPortInstance)
            {
                try
                {
                    string cmd = "", result = "";
                    int value = 0;
                    float fv1 = 0.0f, fv2 = 0.0f;

                    // 读取速度
                    cmd = "01 03 12 12 00 01";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 4);
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    fv1 = fv2 = value;
                    if (fv2 > 0)
                    {
                        fv2 /= 10.0f;
                    }
                    param.SD = fv2.ToString();

                    // 读取模拟量读数
                    cmd = "01 03 14 56 00 01";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 4);
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    param.MNLDS = value.ToString();

                    // 读取当前压力1
                    cmd = "01 03 10 9c 00 02";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine();
                    fv1 = fv2 = (float)JLMUtlity.Get32BitResult(result.Substring(7, 8));
                    param.DQYL1 = fv2.ToString();

                    #region 20241102源 读压力234
                    // 读取当前压力2 10 b6
                    cmd = "01 03 10 b6 00 02";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine();
                    fv1 = fv2 = (float)JLMUtlity.Get32BitResult(result.Substring(7, 8));
                    param.DQYL2 = fv2.ToString();

                    // 读取当前压力3 10 b8
                    cmd = "01 03 10 b8 00 02";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine();
                    fv1 = fv2 = (float)JLMUtlity.Get32BitResult(result.Substring(7, 8));
                    param.DQYL3 = fv2.ToString();

                    // 读取当前压力4 10 ba
                    cmd = "01 03 10 ba 00 02";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine();
                    fv1 = fv2 = (float)JLMUtlity.Get32BitResult(result.Substring(7, 8));
                    param.DQYL4 = fv2.ToString();
                    #endregion

                    // 读取模拟量输出
                    cmd = "01 03 14 5c 00 01";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 4);
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    param.MNLSC = value.ToString();

                    // 读取设置压力值1
                    cmd = "01 03 12 18 00 02";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine();
                    fv1 = fv2 = (float)JLMUtlity.Get32BitResult(result.Substring(7, 8));
                    param.SZYL1 = fv2.ToString();

                    #region 20241102 源 读取设置压力234
                    // 读取设置压力值2
                    cmd = "01 03 11 ae 00 02";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine();
                    fv1 = fv2 = (float)JLMUtlity.Get32BitResult(result.Substring(7, 8));
                    param.SZYL2 = fv2.ToString();

                    // 读取设置压力值3
                    cmd = "01 03 11 b0 00 02";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine();
                    fv1 = fv2 = (float)JLMUtlity.Get32BitResult(result.Substring(7, 8));
                    param.SZYL3 = fv2.ToString();

                    // 读取设置压力值4
                    cmd = "01 03 11 b2 00 02";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine();
                    fv1 = fv2 = (float)JLMUtlity.Get32BitResult(result.Substring(7, 8));
                    param.SZYL4 = fv2.ToString();
                    #endregion
                }
                catch (SystemException se)
                {
                }
            }
        }

        // D536 12 18
        public void WriteTSYMParam(string str, string Address)
        {
            lock (serialPortInstance)
            {
                ushort value = 0;
                byte[] arrayValue = null;
                try
                {
                    value = Convert.ToUInt16(str); // 先转为数字
                    value *= 10;
                    arrayValue = BitConverter.GetBytes(value); // 转为数组
                    Array.Reverse(arrayValue); // 反转

                    // 将值格式化为16进制字符串
                    StringBuilder builder = new StringBuilder();
                    for (int i = 0; i < arrayValue.Length; i++)
                    {
                        builder.Append(string.Format("{0:X2} ", arrayValue[i]));
                    }
                    string hexStringValue = builder.ToString(); // 值的16进制字符串

                    string cmd = "01 06 12 18 " + hexStringValue; // 配置文件中的命令字符串
                    cmd = cmd.ToUpper(); // 替换参数

                    // 计算LRC校验，并组合为PLC命令串
                    string calc = Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16);
                    if (calc.Length == 1)
                    {
                        calc = "0" + calc;
                    }

                    string cmd2 = ":" + cmd + calc + "\r\n";

                    // 移除空格并转为大写
                    cmd2 = cmd2.Replace(" ", "").ToUpper();

                    // 发送
                    serialPortInstance.Write(cmd2);
                    Thread.Sleep(20);
                    // 接收
                    cmd2 = serialPortInstance.ReadLine();
                }
                catch (SystemException se)
                {
                }
            }
        }

        public void Write32BitParam(string Value32Bit, string Address)
        {
            lock (serialPortInstance)
            {
                try
                {
                    var writeValueList = JLMUtlity.Change32BitToHesString(int.Parse(Value32Bit));
                    int Times = 0;
                    writeValueList.ForEach(SingleAddressValue =>
                    {
                        string cmd = $"01 06 {Convert.ToString(Convert.ToInt32(Address.Replace(" ", ""), 16) + Times, 16).Insert(2, " ")} " + SingleAddressValue; // 配置文件中的命令字符串
                        cmd = cmd.ToUpper(); // 替换参数
                        //Utils.WriteLog(this.GetType().ToString(), $"CMD={cmd}");
                        // 计算LRC校验，并组合为PLC命令串
                        string calc = Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16);
                        if (calc.Length == 1)
                        {
                            calc = "0" + calc;
                        }

                        string cmd2 = ":" + cmd + calc + "\r\n";

                        // 移除空格并转为大写
                        cmd2 = cmd2.Replace(" ", "").ToUpper();
                        Utils.WriteLog(this.GetType().ToString() + "WriteTSYMParam32", $"{cmd2}   {SingleAddressValue};");
                        // 发送
                        serialPortInstance.Write(cmd2);
                        Thread.Sleep(20);
                        // 接收
                        cmd2 = serialPortInstance.ReadLine();
                        ++Times;
                    });
                }
                catch (SystemException se) { MessageBox.Show(se.Message); }
            }
        }

        public void ReadTJParam(JLMTJParam param)
        {
            lock (serialPortInstance)
            {
                try
                {
                    string cmd = "", result = "";
                    int value = 0;
                    float fv1 = 0.0f, fv2 = 0.0f;

                    // 读取停机轮面温度 d539
                    cmd = "01 03 12 1b 00 01";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 4);
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    fv1 = fv2 = value;
                    if (fv2 > 0)
                    {
                        fv2 /= 10.0f;
                    }
                    param.TJLMWD = fv2.ToString();

                    // 停机轮毂温度
                    cmd = "01 03 12 1d 00 01";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 4);
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    fv1 = fv2 = value;
                    if (fv2 > 0)
                    {
                        fv2 /= 10.0f;
                    }
                    param.TJLGWD = fv2.ToString();

                    // 读取最高轮面温度
                    cmd = "01 03 12 21 00 01";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 4);
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    fv1 = fv2 = value;
                    if (fv2 > 0)
                    {
                        fv2 /= 10.0f;
                    }
                    param.TJZGLMWD = fv2.ToString();

                    // 读取最高轮毂温度
                    cmd = "01 03 12 23 00 01";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 4);
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    //param.TJZGLGWD = value.ToString();
                    fv1 = value;
                    if (fv1 > 0)
                    {
                        fv1 = fv1 / 10.0f;
                    }
                    param.TJZGLGWD = fv1.ToString();


                    // 读取最高温出现的分
                    cmd = "01 03 11 f6 00 01";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 4);
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    param.TJZGWDFEN = value.ToString();

                    // 读取最高温出现的秒
                    cmd = "01 03 11 f7 00 01";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 4);
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    param.TJZGWDMIAO = value.ToString();

                    // 读取最高内温出现的分
                    cmd = "01 03 11 f8 00 01";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 4);
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    param.TJZGNWFEN = value.ToString();

                    // 读取最高内温出现的分
                    cmd = "01 03 11 f9 00 01";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 4);
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    param.TJZGNWMIAO = value.ToString();

                    // 读取停机时的电机扭矩
                    cmd = "01 03 12 1f 00 01";
                    cmd = ":" + cmd + Convert.ToString(JLMUtlity.CalcLRC(JLMUtlity.HexStringToHexBuffer(cmd)), 16) + "\r\n";
                    cmd = cmd.Replace(" ", "").ToUpper();
                    // 发送
                    serialPortInstance.Write(cmd);
                    Thread.Sleep(20);
                    // 接收
                    result = serialPortInstance.ReadLine(); result = result.Substring(7, 4);
                    value = int.Parse(result, System.Globalization.NumberStyles.HexNumber);
                    // param.SZYL = value.ToString();
                    fv1 = fv2 = value;
                    if (value > 0)
                    {
                        fv2 /= 10.0f;
                    }
                    param.TJDJNJ = fv2.ToString();
                }
                catch (SystemException se)
                {
                }
            }
        }

    }// end of class
}